package constant.milk.toilet.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import constant.milk.toilet.R;
import constant.milk.toilet.util.MilkUtil;

public class MilkPushDialog extends Dialog
{
	private Context context;
	private float TEXT_SIZE;
	
	private View contentView;
	private TextView push3TextView;
	private TextView push5TextView;
	private TextView push7TextView;
	private TextView push10TextView;
	private TextView push15TextView;
	private TextView push30TextView;
	
	private PushCollBank collbank = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.dialog_push);
		
		setSettingFontSize();
		
		setFindView();
		setOnClick();
		setData();
	}

	private void setFindView()
	{
		contentView = findViewById(R.id.dialogPushContentView);
		push3TextView = (TextView) findViewById(R.id.dialogPush3TextView);
		push5TextView = (TextView) findViewById(R.id.dialogPush5TextView);
		push7TextView = (TextView) findViewById(R.id.dialogPush7TextView);
		push10TextView = (TextView) findViewById(R.id.dialogPush10TextView);
		push15TextView = (TextView) findViewById(R.id.dialogPush15TextView);
		push30TextView = (TextView) findViewById(R.id.dialogPush30TextView);
	}
	
	private void setOnClick()
	{
		contentView.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				dismiss();
			}
		});
		
		push3TextView.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				collbank.getPush(3);
				dismiss();
			}
		});
		
		push5TextView.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				collbank.getPush(5);
				dismiss();
			}
		});
		
		push7TextView.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				collbank.getPush(7);
				dismiss();
			}
		});
		
		push10TextView.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				collbank.getPush(10);
				dismiss();
			}
		});
		
		push15TextView.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				collbank.getPush(15);
				dismiss();
			}
		});
		
		push30TextView.setOnClickListener(new View.OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				collbank.getPush(30);
				dismiss();
			}
		});
	}
	
	private void setData()
	{
		push3TextView.setTextSize(TEXT_SIZE);
		push5TextView.setTextSize(TEXT_SIZE);
		push7TextView.setTextSize(TEXT_SIZE);
		push10TextView.setTextSize(TEXT_SIZE);
		push15TextView.setTextSize(TEXT_SIZE);
		push30TextView.setTextSize(TEXT_SIZE);
		
		push3TextView.setTextColor(Color.BLACK);
		push5TextView.setTextColor(Color.BLACK);
		push7TextView.setTextColor(Color.BLACK);
		push10TextView.setTextColor(Color.BLACK);
		push15TextView.setTextColor(Color.BLACK);
		push30TextView.setTextColor(Color.BLACK);
	}

	public MilkPushDialog(Context context, PushCollBank pushCollBank)
	{
		super(context, android.R.style.Theme_Translucent_NoTitleBar);
		
		this.context = context;
		this.collbank = pushCollBank;
	}
	
	private void setSettingFontSize()
	{
		int fontSize = 9;
		
		SharedPreferences p = context.getSharedPreferences("pref", Activity.MODE_PRIVATE);
		int fontFlag = p.getInt(context.getString(R.string.prefFont), 1);
		
		if (fontFlag == 0) fontSize = 13;
		else if (fontFlag == 1) fontSize = 16;
		else if (fontFlag == 2) fontSize = 20;
		
		TEXT_SIZE = fontSize;
	}
	
	public interface PushCollBank
	{
		public abstract void getPush(int pushTime);
	}
}
